package com.swmsss.android_message_receiver;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;

public class MessageReceiverActivity extends Activity implements OnCheckedChangeListener {
    /** Called when the activity is first created. */
	Context mContext;
	ToggleButton toggleButton01;
	BroadcastReceiver receiver;
	IntentFilter filter;
	SharedPreferences pref;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mContext = this;
        
        toggleButton01 = (ToggleButton)findViewById(R.id.toggleButton1);
        toggleButton01.setOnCheckedChangeListener(this);
        
        receiver = new MessageReceiver();
        filter = new IntentFilter();
        filter.addAction("android.provider.Telephony.SMS_RECEIVED");
//        filter.addAction("android.provider.Telephony.WAP_PUSH_RECEIVED"); //MMS
        
        pref = getSharedPreferences("com.swmsss.android_message_receiver", Activity.MODE_PRIVATE);
    }
    
    public void onResume() {
    		super.onResume();
    		
    		//restore toggle button on/off states
    		boolean bReceiveMessages = pref.getBoolean("ReceiveMessages", false);
		toggleButton01.setChecked(bReceiveMessages);
    }

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub
		if(buttonView.getId() == R.id.toggleButton1) {
			//save the boolean into SharedPreferences
			SharedPreferences.Editor editor = pref.edit();
			editor.putBoolean("ReceiveMessages", isChecked);
			editor.commit();
		} else {
			
		}
	}
}